<?php

class News_ManageController extends Zend_Controller_Action
{
	private $Form;
	
	public function init()
	{
	}
	public function indexAction()
	{
	
	}
	public function addAction()
	{
		$id=$this->_getParam('id');
		//echo $id.'   xfdfd';exit;
		if($id!=0)
		{
			$contbid= Doctrine::getTable('News')->getNewsDetails($id);
			$this->view->id=$contbid['id'];
			$this->view->ctitle=$contbid['news_title'];
			$this->view->cdesc=$contbid['news_desc'];
		}
		else
		{  
			$this->view->id="";
			$this->view->ctitle="";
			$this->view->cdesc="";
		}
	}	
	public function saveAction()
	{
		//echo '<pre>';print_r($_POST);exit;
		$id = $_POST['id'];
		if($_POST['id']=='') {
			$contentSaved = Doctrine::getTable('News')->addContent($_POST);
			
			$this->_redirect('/admin-mvc/news/manage/');
		} else {
			$contentSaved = Doctrine::getTable('News')->addContent($_POST);
			
			$this->_redirect('/admin-mvc/news/manage/');
		}
	}
	public function listNewsAction()
	{
		$currentPage = isset($_POST['page'])? $_POST['page']:1;
		$resultsPerPage = isset($_POST['rp'])? $_POST['rp']:10;
		$quickSearchType = isset($_POST['qtype'])? $_POST['qtype']:'';
		$query = isset($_POST['query'])? $_POST['query']:'';
		$sortName = $_POST['sortname'];
		$sortOrder = $_POST['sortorder'];	  	
		$letterPressed=isset($_POST['letter_pressed'])? $_POST['letter_pressed'] :'';
		////////for get the details of manage sector grid///////////////////
		$pager=Doctrine::getTable('News')->getSiteContentGrid($currentPage,$resultsPerPage,$quickSearchType,$query,$sortName,$sortOrder,$letterPressed);
		$res = $pager->execute(array(1), Doctrine::HYDRATE_ARRAY);
		$total = $pager->getNumResults();
		
		$rows = NULL;
		
		foreach($res as $result) {
			$row =& $rows[];
			$row['id'] = $result['id'];
			$row['cell'][] = $result['id'];
			$row['cell'][] = $result['news_title'];
			$row['cell'][] = substr(strip_tags($result['news_desc']),0,100);
			$row['cell'][] = $result['created_date'];
			//$row['cell'][] = $result['created_by'];
			$row['cell'][] = $result['modified_date'];
			///$row['cell'][] = $result['modified_by'];
			if($result['status']==0){
				$row['cell'][] = 'De-Active';
			} else {
				$row['cell'][] = 'Active';
			}	
		}
		$jsonData['page'] = $currentPage;
		$jsonData['total'] = $total;
		$jsonData['rows']  = $rows;
		$this->_helper->json->sendJson($jsonData);
	}
	
	public function activateAction()
	{
		$items = rtrim($_POST['items'],",");
		$result=Doctrine::getTable('News')->activateNews($items);
		$jsonData['total'] = $result;
		$this->_helper->json->sendJson($jsonData);
	}
	
	public function deActivateAction()
	{
		$items = rtrim($_POST['items'],",");
		$result=Doctrine::getTable('News')->deactivateNews($items);
		$jsonData['total'] = $result;
		$this->_helper->json->sendJson($jsonData);
	}
	
	public function deleteAction()
	{
		$items = rtrim($_POST['items'],",");
		$result=Doctrine::getTable('News')->deleteNews($items);
		
		$jsonData['total'] = count(explode(",", $items));
		$this->_helper->json->sendJson($jsonData);
	}
		
	
	
	
}
?>